﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FineUI;
using Maticsoft.BLL;
using Maticsoft.Model;

namespace FineUI.Examples
{
    public partial class teacher_query_share : System.Web.UI.Page
    {
        protected DataSet LoadStuDocment()
        {
            string currentT_Id = Session["UserName"].ToString();
            Maticsoft.BLL.Teacher Teacher = new Maticsoft.BLL.Teacher();
            DataSet DSStudentCourseInform = Teacher.GetReportSubmitInformation("ReportSubmit.T_Id=Teacher.T_Id and ReportSubmit.S_Id=Student.S_Id and Teacher.T_Id= '" + currentT_Id + "'");

            DataView DSView = DSStudentCourseInform.Tables[0].DefaultView;
            Grid1.DataSource = DSView;
            Grid1.DataBind();

            return DSStudentCourseInform;

        }
        protected void ExistsPermiss(string P_Id, string P_Status)
        {
            Maticsoft.BLL.Permissions PM = new Maticsoft.BLL.Permissions();
            if (!PM.ExistsPermiss(P_Id, P_Status))
            {
                Response.Redirect("~/user_no_permission.aspx");
            }

        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserName"] == null)
            {
                Response.Redirect("~/login.aspx");
                return;
            }
            ExistsPermiss("T005", "已授权");
            LoadStuDocment();
        }



        protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
        {
            Grid1.PageIndex = e.NewPageIndex;
            LoadStuDocment();
        }

        protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == "ActionShare")
            {
                int index = e.RowIndex;
                DataSet currentDS = LoadStuDocment();
                string currentRS_Id = currentDS.Tables[0].Rows[index]["RS_Id"].ToString();
                string currentT_Id = currentDS.Tables[0].Rows[index]["T_Id"].ToString();
                string currentS_Id = currentDS.Tables[0].Rows[index]["S_Id"].ToString();
                Maticsoft.BLL.ReportSubmit RS = new Maticsoft.BLL.ReportSubmit();
                Maticsoft.Model.ReportSubmit RS_Inform = RS.GetModel(currentRS_Id, currentT_Id, currentS_Id);
                RS_Inform.RS_Share = "已共享";
                if (RS.Update(RS_Inform))
                {
                    LoadStuDocment();
                }
            
            }

            if (e.CommandName == "ActionCancel")
            {
                int index = e.RowIndex;
                DataSet currentDS = LoadStuDocment();
                string currentRS_Id = currentDS.Tables[0].Rows[index]["RS_Id"].ToString();
                string currentT_Id = currentDS.Tables[0].Rows[index]["T_Id"].ToString();
                string currentS_Id = currentDS.Tables[0].Rows[index]["S_Id"].ToString();
                Maticsoft.BLL.ReportSubmit RS = new Maticsoft.BLL.ReportSubmit();
                Maticsoft.Model.ReportSubmit RS_Inform = RS.GetModel(currentRS_Id, currentT_Id, currentS_Id);
                RS_Inform.RS_Share = "未共享";
                if (RS.Update(RS_Inform))
                {
                    LoadStuDocment();
                }

            }
        }
    }
}